﻿@{    
    //page title
    ViewBag.Title = T("Admin.Configuration.Plugins").Text;
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "plugins-form" }))
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
            @T("Admin.Configuration.Plugins")
        </div>
        <div class="options">
            <a href="@Url.Action("ReloadList")" class="k-button">@T("Admin.Configuration.Plugins.ReloadList")</a>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#plugins-grid").on("click", ".install-plugin-link", function (e) {
                showThrobber('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Admin.Configuration.Plugins.Fields.Install.Progress").Text))');
            });

            $("#plugins-grid").on("click", ".uninstall-plugin-link", function (e) {
                showThrobber('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Admin.Configuration.Plugins.Fields.Uninstall.Progress").Text))');
            });
        });
    </script>    
    <table class="adminContent">
        <tr>
            <td>
                <h4>@T("Admin.Configuration.Plugins.Description"):</h4>
                <ol>
                    <li>@T("Admin.Configuration.Plugins.Description.Step1")</li>
                    <li>@T("Admin.Configuration.Plugins.Description.Step2")</li>
                    <li>@T("Admin.Configuration.Plugins.Description.Step3")</li>
                    <li>@T("Admin.Configuration.Plugins.Description.Step4")</li>
                    <li>@T("Admin.Configuration.Plugins.Description.Step5")</li>
                </ol>
                <p>
                    You can download more nopCommerce plugins on our <a href="http://www.nopcommerce.com/extensions-and-themes.aspx" target="_blank">extensions directory</a>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <div id="plugins-grid"></div>

                <script>
                    $(document).ready(function() {
                        $("#plugins-grid").kendoGrid({
                            dataSource: {
                                type: "json",
                                transport: {
                                    read: {
                                        url: "@Html.Raw(Url.Action("ListSelect", "Plugin"))",
                                        type: "POST",
                                        dataType: "json"
                                    }
                                },
                                schema: {
                                    data: "Data",
                                    total: "Total",
                                    errors: "Errors"
                                },
                                error: function(e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                serverPaging: true,
                                serverFiltering: true,
                                serverSorting: true
                            },
                            pageable: {
                                refresh: true,
                                numeric: false,
                                previousNext: false,
                                info: false
                            },
                            editable: {
                                confirmation: false,
                                mode: "inline"
                            },
                            scrollable: false,
                            columns: [
                                {
                                    field: "Group",
                                    title: "@T("Admin.Configuration.Plugins.Fields.Group")"
                                }, {
                                    field: "LogoUrl",
                                    title: "@T("Admin.Configuration.Plugins.Fields.Logo")",
                                    width: 100,
                                    template: '<img src="#=LogoUrl#" />',
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" }
                                }, {
                                    field: "FriendlyName",
                                    title: "@T("Admin.Configuration.Plugins.Info")",
                                    template: '<b>#:FriendlyName#</b>' +
                                        '<br />@T("Admin.Configuration.Plugins.Fields.Version"): #:Version#' +
                                        '<br />@T("Admin.Configuration.Plugins.Fields.Author"): #:Author#' +
                                        '<br />@T("Admin.Configuration.Plugins.Fields.SystemName"): #:SystemName#' +
                                        '<br />@T("Admin.Configuration.Plugins.Fields.DisplayOrder"): #:DisplayOrder#' +
                                        '<br />@T("Admin.Configuration.Plugins.Fields.Installed"): <img src="@Url.Content("~/Administration/Content/images/")active-#=Installed#.gif" />' +
                                        '# if(CanChangeEnabled) {# <br />@T("Admin.Configuration.Plugins.Fields.IsEnabled"): <img src="@Url.Content("~/Administration/Content/images/")active-#=IsEnabled#.gif" /> #} #' +
                                        //allow configuration only when a plugin has a configuration URL specified
                                        '<br /># if(ConfigurationUrl && ConfigurationUrl.length > 0) {# <a class="plugin-button plugin-button-configure" href="#=ConfigurationUrl#">@T("Admin.Configuration.Plugins.Fields.Configure")</a>&nbsp;&nbsp;&nbsp; #} #' +
                                        '<a class="plugin-button plugin-button-edit" href="javascript:OpenWindow(\'@Url.Content("~/Admin/Plugin/EditPopup")?systemName=#=SystemName#&btnId=btnRefresh&formId=plugins-form\', 800, 300, true);">@T("Admin.Common.Edit")</a>'
                                }, {
                                    field: "Installed",
                                    title: "@T("Admin.Configuration.Plugins.Fields.Installation")",
                                    template: '# if(Installed) {# <a href="@Url.Content("~/Admin/Plugin/Uninstall/")?systemName=#=SystemName#" class="plugin-button uninstall-plugin-link">@T("Admin.Configuration.Plugins.Fields.Uninstall")<a/> #} else {#  <a href="@Url.Content("~/Admin/Plugin/Install/")?systemName=#=SystemName#" class="plugin-button install-plugin-link">@T("Admin.Configuration.Plugins.Fields.Install")<a/> #} #',
                                    headerAttributes: {style: "text-align:center" },
                                    attributes: { style: "text-align:center" }
                                }
                            ]
                        });
                    });
                </script>
            </td>
        </tr>
        <tr>
            <td width="100%">
                <input type="submit" id="btnRefresh" name="btnRefresh" style="display: none" />
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#btnRefresh').click(function () {
                            //refresh grid
                            var grid = $("#plugins-grid").data('kendoGrid');
                            //grid.dataSource.page(1); //new search. Set page size to 1
                            grid.dataSource.read();

                            //return false to don't reload a page
                            return false;
                        });
                    });
                </script>
            </td>
        </tr>
    </table>
}